package gen.tools.jenkins;

import gen.tools.Widgets;
import gen.tools.structures.BeFailure;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class QueryBeFailure extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public QueryBeFailure() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		final Widgets wid = new Widgets();
		response.setCharacterEncoding( wid.UIcodeSet );
		response.setContentType("application/json");
		
		List<BeFailure> befs = null; 
		
		
		try {
			/*//從AP Server的JNDI取得data source
			Context ctx = new InitialContext();
			DataSource dataSource = (DataSource) ctx.lookup( wid.JNDINAME );
			
			JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
			String sql = "SELECT t1.subsysId,t3.subsysDesc,t1.chkInMainId,t1.isUrgent,t1.isDailyBuild,t1.cmFileVer,t2.empName,t1.cDT FROM chkinmain t1, emps t2,subsyses t3 WHERE t1.subsysId=t3.subsysId AND t1.creatorId=t2.empId AND t1.chkInStatusId=8 ORDER BY t1.chkinMainId DESC";			
			
			befs = jdbcTemplate.query(sql,
				new RowMapper<BeFailure>() {
                	public BeFailure mapRow(ResultSet rs, int rowNum) throws SQLException {
                		return new BeFailure(
                			rs.getString("subsysId"),
                			rs.getString("subsysDesc"),
                			rs.getInt("chkInMainId"),
                			"t".equalsIgnoreCase(rs.getString("isUrgent")),
                			"t".equalsIgnoreCase(rs.getString("isDailyBuild")),
                			rs.getInt("cmFileVer"),
                			rs.getString("empName"),
                			wid.changeTimeFormat(rs.getTimestamp("cDT"))
                		);
                	}
            });*/
		} catch (Exception e) {
			wid.errLog(e);
		}
		
		response.getWriter().write( new Gson().toJson(befs) );
		
	}

}
